package com.geese.module.business.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.geese.common.BaseController;
import com.geese.common.constants.Constants;
import com.geese.common.entity.Business;
import com.geese.common.vo.Page;
import com.geese.common.vo.Paginator;
import com.geese.module.business.dto.OrderBusinessDto;
import com.geese.module.business.service.BusinessService;
import com.geese.module.business.vo.OrderBusinessQuery;
import com.geese.module.ceo.service.OrderService;
import com.geese.module.user.model.SecurityUser;
import com.geese.module.user.service.UserService;
import com.google.common.collect.Maps;

/** 
 * Created by yefangyi
 */
@Controller
@RequestMapping(value = "/business")
@Scope("prototype")
public class OrderBusinessController extends BaseController {

    @Autowired
    private UserService userService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private BusinessService businessService;

    /**
     * 获取小二订单列表
     */
    @ResponseBody
    @GetMapping("/order/listInPage")
    public String listOrderInPage(OrderBusinessQuery query) {
    	SecurityUser user = userService.getLoginUser(query.getToken());
    	Business business = businessService.findByUserId(user.getUserId());
    	
    	Page page = getPageInfo(query);
    	Paginator<OrderBusinessDto> pageList = orderService.listAllByBusiness(query, business.getId(), page);
    	Map<String, Object> result = Maps.newHashMap();
    	result.put(Constants.PAGE_INFO, pageList.getPageResult());
    	result.put("orderList", pageList.getResults());
        return response(result);
    }


}
